<template>
<div class="container">
  <div class="top flex">
    <a href="javascript:;"
      class="nav flex-1"
      v-for="(item ,index) in navList"
      v-text="item.text"
      :class="{active: item.isActive}"
      @click.once="navTap(index)"
      @click="navActive(index)"></a>
    <!-- <a href="javascript:;" class="nav flex-1">已生效</a>
    <a href="javascript:;" class="nav flex-1">待支付</a>
    <a href="javascript:;" class="nav flex-1">已解约</a>
    <a href="javascript:;" class="nav flex-1">已到期</a> -->
  </div>
  <div class="list-wrap" v-show="navList[0].isActive">
    <router-link 
      v-for="item in orderList1"
      :to="{path:'/OrderDetail',query:{orderId:item.orderId}}" 
      class="order"
      :key="item.orderId">
      <div class="top-bar">
        {{item.productName}}
        <span class="tag unpay" v-if="item.orderStatus==0">待支付</span>
        <span class="tag effect" v-if="item.orderStatus==1">已生效</span>
        <span class="tag outdeal" v-if="item.orderStatus==3">已解约</span>
        <span class="tag outdeal" v-if="item.orderStatus==5">已到期</span>
        <!-- 已生效:effect
        已解约:outdeal -->
      </div>
      <div class="middle flex">
        <div class="m-l">
          <img :src="item.logoUrl" :onerror="defaultImg" alt="">
        </div>
        <div class="m-r flex-1" v-text="item.productInfo">
        </div>
      </div>
      <div class="bottom">
        <div class="b-l">产品编号：{{item.productNumber}}</div>
        <div class="b-r" v-text="item.priceType"></div>
      </div>
    </router-link>

  </div>
  <!-- 已生效 -->
  <div class="list-wrap" v-show="navList[1].isActive">
    <router-link to="/OrderDetail" class="order"
      v-for="item in orderList2"
      :key="item.orderId">
      <div class="top-bar">
        {{item.productName}}
        <span class="tag unpay" v-if="item.orderStatus==0">待支付</span>
        <span class="tag effect" v-if="item.orderStatus==1">已生效</span>
        <span class="tag outdeal" v-if="item.orderStatus==3">已解约</span>
        <!-- 已生效:effect
        已解约:outdeal -->
      </div>
      <div class="middle flex">
        <div class="m-l">
          <img :src="item.logoUrl" :onerror="defaultImg" alt="">
        </div>
        <div class="m-r flex-1" v-text="item.productInfo">
        </div>
      </div>
      <div class="bottom">
        <div class="b-l">产品编号：{{item.productNumber}}</div>
        <div class="b-r" v-text="item.priceType"></div>
      </div>
    </router-link>

  </div>
  <!-- 待支付 -->
  <div class="list-wrap" v-show="navList[2].isActive">
    <router-link to="/OrderDetail" class="order"
      v-for="item in orderList3"
      :key="item.orderId">
      <div class="top-bar">
        {{item.productName}}
        <span class="tag unpay" v-if="item.orderStatus==0">待支付</span>
        <span class="tag effect" v-if="item.orderStatus==1">已生效</span>
        <span class="tag outdeal" v-if="item.orderStatus==3">已解约</span>
        <!-- 已生效:effect
        已解约:outdeal -->
      </div>
      <div class="middle flex">
        <div class="m-l">
          <img :src="item.logoUrl" :onerror="defaultImg" alt="">
        </div>
        <div class="m-r flex-1" v-text="item.productInfo">
        </div>
      </div>
      <div class="bottom">
        <div class="b-l">产品编号：{{item.productNumber}}</div>
        <div class="b-r" v-text="item.priceType"></div>
      </div>
    </router-link>
  </div>
  <!-- 已解约 -->
  <div class="list-wrap" v-show="navList[3].isActive">
    <router-link to="/OrderDetail" class="order"
      v-for="item in orderList4"
      :key="item.orderId">
      <div class="top-bar">
        {{item.productName}}
        <span class="tag unpay" v-if="item.orderStatus==0">待支付</span>
        <span class="tag effect" v-if="item.orderStatus==1">已生效</span>
        <span class="tag outdeal" v-if="item.orderStatus==3">已解约</span>
        <!-- 已生效:effect
        已解约:outdeal -->
      </div>
      <div class="middle flex">
        <div class="m-l">
          <img :src="item.logoUrl" :onerror="defaultImg" alt="">
        </div>
        <div class="m-r flex-1" v-text="item.productInfo">
        </div>
      </div>
      <div class="bottom">
        <div class="b-l">产品编号：{{item.productNumber}}</div>
        <div class="b-r" v-text="item.priceType"></div>
      </div>
    </router-link>
  </div>
  <!-- 已到期 -->
  <div class="list-wrap" v-show="navList[4].isActive">
    <router-link to="/OrderDetail" class="order"
      v-for="item in orderList5"
      :key="item.orderId">
      <div class="top-bar">
        {{item.productName}}
        <span class="tag unpay" v-if="item.orderStatus==0">待支付</span>
        <span class="tag effect" v-if="item.orderStatus==1">已生效</span>
        <span class="tag outdeal" v-if="item.orderStatus==3">已解约</span>
        <span class="tag outdeal" v-if="item.orderStatus==5">已到期</span>
        <!-- 已生效:effect
        已解约:outdeal -->
      </div>
      <div class="middle flex">
        <div class="m-l">
          <img :src="item.logoUrl" :onerror="defaultImg" alt="">
        </div>
        <div class="m-r flex-1" v-text="item.productInfo">
        </div>
      </div>
      <div class="bottom">
        <div class="b-l">产品编号：{{item.productNumber}}</div>
        <div class="b-r" v-text="item.priceType"></div>
      </div>
    </router-link>
  </div>
</div>

</template>

<script>
import Api from '@/service';
import Tip from '@/tools';
export default {
  name: 'MyOrder',
  data () {
    return {
      orderList1: [],
      orderList2: [],
      orderList3: [],
      orderList4: [],
      orderList5: [],
      pageIndex: 0,
      totalPage: 0,
      navList: [
      {text: "全部",isActive: true},
      {text: "已生效",isActive: false},
      {text: "待支付",isActive: false},
      {text: "已解约",isActive: false},
      {text: "已到期",isActive: false}
      ],
      defaultImg: Tip.tips.res.defaultImg
    }
  },
  methods: {
    getPage1(){
      let _self = this;
      _self.getPageOrder(10,10,1).then(response => {
        console.log(response.data.info);
        if(response.data.info.orderList){
          _self.orderList1 = response.data.info.orderList;
        }
      })

    },
    getPageOrder(status,pageSize,currentPage){
      // 10,10,1
      return Api.sm.initMyOrder(status,pageSize,currentPage,"7dqj7l4DUDgaAI2ysfZiXoeZlxXZZyRoE5Z0j1moya0*");
    },
    navActive(_index){
      let _self = this;

      // nav激活
      for(let i=0,j=_self.navList.length; i<j; i++ ){
        _self.navList[i].isActive = false;
      }
      _self.navList[_index].isActive = true;
    },
    navTap(_index){
      let _self = this;
      // 获取数据
      if(_index==1){
        _self.getPageOrder(1,10,1).then(response => {
          console.log(response.data.info);
          if(response.data.info.orderList){
            _self.orderList2 = response.data.info.orderList;
          }
        });
      }else if(_index==2){
        _self.getPageOrder(0,10,1).then(response => {
          console.log(response.data.info);
          if(response.data.info.orderList){
            _self.orderList3 = response.data.info.orderList;
          }
        });

      }else if(_index==3){
        _self.getPageOrder(3,10,1).then(response => {
          console.log(response.data.info);
          if(response.data.info.orderList){
            _self.orderList4 = response.data.info.orderList;
          }
        });
        
      }else if(_index==4){
        _self.getPageOrder(5,10,1).then(response => {
          console.log(response.data.info);
          if(response.data.info.orderList){
            _self.orderList5 = response.data.info.orderList;
          }
        });
        
      }

    }

  },
  created: function(){
    this.getPage1();
  }
}
</script>

<style lang="scss" scoped type="text/css">
@import  "../assets/scss/reset";
.container{
  width: 100%;
  background: #F5F8FA;
  overflow: hidden;
  .top{
    width: 100%;
    height: calculateRem(40px);
    background: #f5f8fa;
    box-sizing: border-box;
    border-bottom: 1px solid #e5e8ea;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    .nav{
      display: inline-block;
      height: calculateRem(40px);
      line-height: calculateRem(40px);
      max-width: 20%;
      text-align: center;
      color: #2B2E33;
      font-size: calculateRem(15px);
      position: relative;
      &:active{
        background: #ecf3f7;
      }
      &:after{
        content: '';
        display: inline-block;
        width: 1px;
        background: #D5D8DC;
        height: calculateRem(15px);
        position: absolute;
        right: 0;
        top: calculateRem(12px);

      }
      &:last-child{
        &:after{
          display: none;
        }
      }
    }
    .active{
      position: relative;
      color: #F21612;
      &:before{
        content: '';
        display: inline-block;
        position: absolute;
        bottom: 0;
        left: calculateRem(14px);
        right: calculateRem(14px);
        background: #F21612;
        height: 2px;
      }
    }
  }
  .list-wrap{
    width: 100%;
    height: auto;
    box-sizing: border-box;
    padding-top: calculateRem(40px);
    overflow: hidden;
    .order{
      display: block;
      background: white;
      padding: 0 calculateRem(16px);
      margin-bottom: calculateRem(10px);
      .top-bar{
        position: relative;
        width: 100%;
        height: calculateRem(50px);
        line-height: calculateRem(50px);
        box-sizing: border-box;
        border-bottom: 1px solid #D8D8D8;
        font-size: calculateRem(16px);
        color: black;
        padding-right: calculateRem(50px);
        @include ell;
        .tag{
          display: inline-block;
          width: calculateRem(48px);
          height: calculateRem(22px);
          line-height: calculateRem(20px);
          box-sizing: border-box;
          text-align: center;
          font-size: calculateRem(12px);
          border-radius: 3px;
          position: absolute;
          right: 0;
          top: calculateRem(14px);
        }
        .unpay{
          color: #FF703A;
          border: 1px solid #FF703A;
        }
        .effect{
          color: #2F9AD8;
          border: 1px solid #2F9AD8;
        }
        .outdeal{
          color: #999;
          border: 1px solid #999;
        }
      }
      .middle{
        width: 100%;
        height: auto;
        box-sizing: border-box;
        padding: calculateRem(16px) 0;
        .m-l{
          width: calculateRem(40px);
          height: calculateRem(40px);
          margin-right: calculateRem(14px);
          >img{
            width: 100%;
            height: 100%;
          }

        }
        .m-r{ 
          height: calculateRem(40px);
          max-width: 83%;
          line-height: calculateRem(20px);
          @include mulell(2);
          overflow: hidden;
          font-size: calculateRem(14px);
          color: #4B4B4B;

        }
      }
      .bottom{
        width: 100%;
        height: calculateRem(46px);
        line-height: calculateRem(46px);
        box-sizing: border-box;
        border-top: 1px solid #d8d8d8;
        font-size: calculateRem(15px);
        color: #4B4B4B;
        .b-l{
          width: 70%;
          height: calculateRem(46px);
          float: left;
          @include ell;
        }
        .b-r{
          width: 30%;
          height: calculateRem(46px);
          float: right;
          text-align: right;
          @include ell;
        }
      }
    }
  }
}
</style>
